#ifndef MYMODBUS_H
#define MYMODBUS_H

#include <QModbusDataUnit>
#include <QObject>
#include <QModbusClient>
#include <QTimer>
#include <QSqlDatabase>
#include <QVariantList>
#include <QVariantMap>
#include <QSerialPort>
#include <QVector>
#include <QJsonArray> // [ ]
#include <QMutex>
#include <QReadWriteLock>
#include "myprinter/myprinter.h"
QT_BEGIN_NAMESPACE

class QModbusClient;
class QModbusReply;

QT_END_NAMESPACE
enum Endian
{
    LittileEndian,
    BigEndian
};
class MyModBus: public QObject
{
    Q_OBJECT
    Q_PROPERTY(QStringList comData READ comData CONSTANT)
    Q_PROPERTY(QString comName READ comName  NOTIFY comNameChanged)
    Q_PROPERTY(int baudrate READ baudrate  NOTIFY baudrateChanged)
    Q_PROPERTY(int dataBit READ dataBit  NOTIFY dataBitChanged)
    Q_PROPERTY(int stopBit READ stopBit  NOTIFY stopBitChanged)
    Q_PROPERTY(int parity READ parity  NOTIFY parityChanged)

    Q_PROPERTY(QString comName4g READ comName4g  NOTIFY comName4gChanged)
    Q_PROPERTY(int baudrate4g READ baudrate4g  NOTIFY baudrate4gChanged)
    Q_PROPERTY(int dataBit4g READ dataBit4g  NOTIFY dataBit4gChanged)
    Q_PROPERTY(int stopBit4g READ stopBit4g  NOTIFY stopBit4gChanged)
    Q_PROPERTY(int parity4g READ parity4g  NOTIFY parity4gChanged)

    Q_PROPERTY(QString comNameEncoder READ comNameEncoder  NOTIFY comNameEncoderChanged)
    Q_PROPERTY(int baudrateEncoder READ baudrateEncoder  NOTIFY baudrateEncoderChanged)
    Q_PROPERTY(int dataBitEncoder READ dataBitEncoder  NOTIFY dataBitEncoderChanged)
    Q_PROPERTY(int stopBitEncoder READ stopBitEncoder  NOTIFY stopBitEncoderChanged)
    Q_PROPERTY(int parityEncoder READ parityEncoder  NOTIFY parityEncoderChanged)

    Q_PROPERTY(QString softwareVersion READ softwareVersion  NOTIFY softwareVersionChanged)
    Q_PROPERTY(QString devDate READ devDate  NOTIFY devDateChanged)
    Q_PROPERTY(QString weight READ weight  NOTIFY weightChanged)
    Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY decimalPlacesChanged)
    Q_PROPERTY(int minGraduation READ minGraduation WRITE setMinGraduation NOTIFY minGraduationChanged)
    Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
    Q_PROPERTY(double upperUpperLimit READ upperUpperLimit WRITE setUpperUpperLimit NOTIFY upperUpperLimitChanged)
    Q_PROPERTY(double upperLimit READ upperLimit WRITE setUpperLimit NOTIFY upperLimitChanged)
    Q_PROPERTY(double lowerLimit READ lowerLimit WRITE setLowerLimit NOTIFY lowerLimitChanged)
    Q_PROPERTY(double lowerLowerLimit READ lowerLowerLimit WRITE setLowerLowerLimit NOTIFY lowerLowerLimitChanged)
    Q_PROPERTY(int steadyStateFiltering READ steadyStateFiltering WRITE setSteadyStateFiltering NOTIFY steadyStateFilteringChanged)
    Q_PROPERTY(int digitalFiltering READ digitalFiltering WRITE setDigitalFiltering NOTIFY digitalFilteringChanged)
    Q_PROPERTY(int slaveID READ slaveID WRITE setSlaveID NOTIFY slaveIDChanged)
    Q_PROPERTY(int stabilityRange READ stabilityRange WRITE setStabilityRange NOTIFY stabilityRangeChanged)
    Q_PROPERTY(int clearRange READ clearRange WRITE setClearRange NOTIFY clearRangeChanged)
    Q_PROPERTY(int powerAutoZero READ powerAutoZero WRITE setPowerAutoZero NOTIFY powerAutoZeroChanged)
    Q_PROPERTY(int zeroTraceRange READ zeroTraceRange WRITE setZeroTraceRange NOTIFY zeroTraceRangeChanged)
    Q_PROPERTY(int aDSampleRate READ aDSampleRate WRITE setADSampleRate NOTIFY aDSampleRateChanged)
    Q_PROPERTY(int maxRange READ maxRange WRITE setMaxRange NOTIFY maxRangeChanged)
    Q_PROPERTY(int holdMode READ holdMode /*WRITE setHoldMode*/ NOTIFY holdModeChanged)
    Q_PROPERTY(int holdTriggerCondition READ holdTriggerCondition /*WRITE setHoldTriggerCondition*/ NOTIFY holdTriggerConditionChanged)
    Q_PROPERTY(int zeroValue READ zeroValue WRITE setZeroValue NOTIFY zeroValueChanged)
    Q_PROPERTY(int holdResult READ holdResult NOTIFY holdResultChanged)
    Q_PROPERTY(int preIsStable1 READ preIsStable1 /*WRITE setPreIsStable1*/ NOTIFY preIsStable1Changed)
    Q_PROPERTY(int preMinDuration1 READ preMinDuration1 /*WRITE setPreMinDuration1*/ NOTIFY preMinDuration1Changed)
    Q_PROPERTY(int preCondition1 READ preCondition1 /*WRITE setPreCondition1*/ NOTIFY preCondition1Changed)
    Q_PROPERTY(int preValue11 READ preValue11 WRITE setPreValue11 NOTIFY preValue11Changed)
    Q_PROPERTY(int preValue21 READ preValue21 WRITE setPreValue21 NOTIFY preValue21Changed)
    Q_PROPERTY(int preIsStable2 READ preIsStable2 NOTIFY preIsStable2Changed)
    Q_PROPERTY(int preMinDuration2 READ preMinDuration2 NOTIFY preMinDuration2Changed)
    Q_PROPERTY(int preCondition2 READ preCondition2 NOTIFY preCondition2Changed)
    Q_PROPERTY(int preValue12 READ preValue12 WRITE setPreValue12 NOTIFY preValue12Changed)
    Q_PROPERTY(int preValue22 READ preValue22 WRITE setPreValue22 NOTIFY preValue22Changed)
    Q_PROPERTY(int preIsStable3 READ preIsStable3 NOTIFY preIsStable3Changed)
    Q_PROPERTY(int preMinDuration3 READ preMinDuration3 NOTIFY preMinDuration3Changed)
    Q_PROPERTY(int preCondition3 READ preCondition3 NOTIFY preCondition3Changed)
    Q_PROPERTY(int preValue13 READ preValue13 WRITE setPreValue13 NOTIFY preValue13Changed)
    Q_PROPERTY(int preValue23 READ preValue23 WRITE setPreValue23 NOTIFY preValue23Changed)
    Q_PROPERTY(int preIsStable4 READ preIsStable4 NOTIFY preIsStable4Changed)
    Q_PROPERTY(int preMinDuration4 READ preMinDuration4 NOTIFY preMinDuration4Changed)
    Q_PROPERTY(int preCondition4 READ preCondition4 NOTIFY preCondition4Changed)
    Q_PROPERTY(int preValue14 READ preValue14 WRITE setPreValue14 NOTIFY preValue14Changed)
    Q_PROPERTY(int preValue24 READ preValue24 WRITE setPreValue24 NOTIFY preValue24Changed)
    Q_PROPERTY(int backlight READ backlight WRITE setbacklight NOTIFY backlightChanged)
    Q_PROPERTY(int screenSaveTime READ screenSaveTime WRITE setScreenSaveTime NOTIFY screenSaveTimeChanged)

    Q_PROPERTY(int stable READ stable NOTIFY stableChanged)
    Q_PROPERTY(int normal READ normal NOTIFY normalChanged)
    Q_PROPERTY(int zero READ zero NOTIFY zeroChanged)
    Q_PROPERTY(int positive READ positive NOTIFY positiveChanged)
    Q_PROPERTY(int batteryLevel READ batteryLevel NOTIFY batteryLevelChanged)
    Q_PROPERTY(int current0 READ current0 NOTIFY current0Changed)
    Q_PROPERTY(int collectTime READ collectTime WRITE setCollectTime NOTIFY collectTimeChanged)

    Q_PROPERTY(int axisCount READ axisCount WRITE setAxisCount NOTIFY axisCountChanged)
    Q_PROPERTY(QString addrs READ addrs WRITE setAddrs NOTIFY addrsChanged)
    Q_PROPERTY(QVariantList factors READ factors CONSTANT)
    Q_PROPERTY(QString qccid READ qccid CONSTANT)
    Q_PROPERTY(QString deviceID READ deviceID NOTIFY deviceIDChanged)
    Q_PROPERTY(QString deviceType READ deviceType NOTIFY deviceTypeChanged)
    Q_PROPERTY(bool cpin READ cpin NOTIFY cpinChanged)

    Q_PROPERTY(QString hostName READ hostName WRITE setHostName NOTIFY hostNameChanged)
    Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
    Q_PROPERTY(QString subTopic READ subTopic WRITE setSubTopic NOTIFY subTopicChanged)
    Q_PROPERTY(QString topic READ topic WRITE setTopic NOTIFY topicChanged)
    Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
    Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
    Q_PROPERTY(QString truckNo READ truckNo WRITE setTruckNo NOTIFY truckNoChanged)
    Q_PROPERTY(QString clientID READ clientID WRITE setClientID NOTIFY clientIDChanged)
    Q_PROPERTY(int mqttSwitch READ mqttSwitch WRITE setMqttSwitch NOTIFY mqttSwitchChanged)
    Q_PROPERTY(int mqttInterval READ mqttInterval WRITE setMqttInterval NOTIFY mqttIntervalChanged)
    Q_PROPERTY(int saveInterval READ saveInterval WRITE setSaveInterval NOTIFY saveIntervalChanged)
    Q_PROPERTY(int pulsePerRev READ pulsePerRev WRITE setPulsePerRev NOTIFY pulsePerRevChanged)

    Q_PROPERTY(QString voltage0 READ voltage0 NOTIFY voltage0Changed)
    Q_PROPERTY(QString voltage1 READ voltage1 NOTIFY voltage1Changed)
    Q_PROPERTY(QString voltage2 READ voltage2 NOTIFY voltage2Changed)
    Q_PROPERTY(QString voltage3 READ voltage3 NOTIFY voltage3Changed)
    Q_PROPERTY(QString voltage4 READ voltage4 NOTIFY voltage4Changed)
    Q_PROPERTY(QString voltage5 READ voltage5 NOTIFY voltage5Changed)
    Q_PROPERTY(QString voltage6 READ voltage6 NOTIFY voltage6Changed)
    Q_PROPERTY(QString voltage7 READ voltage7 NOTIFY voltage7Changed)


//    Q_PROPERTY(int voltage0_ READ voltage0_ NOTIFY voltage0_Changed)
//    Q_PROPERTY(int voltage1_ READ voltage1_ NOTIFY voltage1_Changed)
//    Q_PROPERTY(int voltage2_ READ voltage2_ NOTIFY voltage2_Changed)
//    Q_PROPERTY(int voltage3_ READ voltage3_ NOTIFY voltage3_Changed)
//    Q_PROPERTY(int voltage4_ READ voltage4_ NOTIFY voltage4_Changed)
//    Q_PROPERTY(int voltage5_ READ voltage5_ NOTIFY voltage5_Changed)
//    Q_PROPERTY(int voltage6_ READ voltage6_ NOTIFY voltage6_Changed)
//    Q_PROPERTY(int voltage7_ READ voltage7_ NOTIFY voltage7_Changed)

    Q_PROPERTY(double calThreshold READ calThreshold WRITE setCalThreshold NOTIFY calThresholdChanged)
    Q_PROPERTY(double accumulateZero READ accumulateZero WRITE setAccumulateZero NOTIFY accumulateZeroChanged)

    Q_PROPERTY(int sensorConnStatus READ sensorConnStatus WRITE setSensorConnStatus NOTIFY sensorConnStatusChanged)
    Q_PROPERTY(QString sensorLastRevTime READ sensorLastRevTime WRITE setSensorLastRevTime NOTIFY sensorLastRevTimeChanged)
    Q_PROPERTY(QString _4gLastRevTime READ _4gLastRevTime WRITE set4gLastRevTime NOTIFY _4gLastRevTimeChanged)

    Q_PROPERTY(QString encoderLastRevTime READ encoderLastRevTime WRITE setEncoderLastRevTime NOTIFY encoderLastRevTimeChanged)
    Q_PROPERTY(QString gpsLastRevTime READ gpsLastRevTime WRITE setGpsLastRevTime NOTIFY gpsLastRevTimeChanged)
    Q_PROPERTY(int _4gConnStatus READ _4gConnStatus WRITE set4gConnStatus NOTIFY _4gConnStatusChanged)
    Q_PROPERTY(bool _4gCPIN READ _4gCPIN WRITE set4gCPIN NOTIFY _4gCPINChanged)
    Q_PROPERTY(bool _4gCEREG READ _4gCEREG WRITE set4gCEREG NOTIFY _4gCEREGChanged)
    Q_PROPERTY(bool _4gOpenMqttClient READ _4gOpenMqttClient WRITE set4gOpenMqttClient NOTIFY _4gOpenMqttClientChanged)
    Q_PROPERTY(bool _4gConnMqttClient READ _4gConnMqttClient WRITE set4gConnMqttClient NOTIFY _4gConnMqttClientChanged)
    Q_PROPERTY(QString _4gSignal READ _4gSignal WRITE set4gSignal NOTIFY _4gSignalChanged)
    //_4gSubSuccess
    Q_PROPERTY(bool _4gSubSuccess READ _4gSubSuccess WRITE set4gSubSuccess NOTIFY _4gSubSuccessChanged)

    Q_PROPERTY(QString apn READ apn WRITE setApn NOTIFY apnChanged)
    Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
    Q_PROPERTY(QString version READ version CONSTANT)
    Q_PROPERTY(QString devTime READ devTime CONSTANT)

    Q_PROPERTY(int encoderConnStatus READ encoderConnStatus WRITE setEncoderConnStatus NOTIFY encoderConnStatusChanged)

    Q_PROPERTY(int encoderChannel READ encoderChannel WRITE setEncoderChannel NOTIFY encoderChannelChanged)
    Q_PROPERTY(int encoderFiltering READ encoderFiltering WRITE setEncoderFiltering NOTIFY encoderFilteringChanged)
    Q_PROPERTY(int encoderDirection READ encoderDirection WRITE setEncoderDirection NOTIFY encoderDirectionChanged)
    Q_PROPERTY(int encoderInterval READ encoderInterval WRITE setEncoderInterval NOTIFY encoderIntervalChanged)
    Q_PROPERTY(QString angle READ angle NOTIFY angleChanged)
    Q_PROPERTY(QString weightNew READ weightNew NOTIFY weightNewChanged)
    Q_PROPERTY(QString voltage READ voltage NOTIFY voltageChanged)
    Q_PROPERTY(int encoderDecimalPlace READ encoderDecimalPlace WRITE setEncoderDecimalPlace NOTIFY encoderDecimalPlaceChanged)

    Q_PROPERTY(int sensorSlaveID READ sensorSlaveID WRITE setSensorSlaveID NOTIFY sensorSlaveIDChanged)
    Q_PROPERTY(int encoderSlaveID READ encoderSlaveID WRITE setEncoderSlaveID NOTIFY encoderSlaveIDChanged)

    Q_PROPERTY(bool init READ init WRITE setInit NOTIFY initChanged)
    Q_PROPERTY(bool downloadOTAPackage READ downloadOTAPackage WRITE setDownloadOTAPackage NOTIFY downloadOTAPackageChanged)
    Q_PROPERTY(QVariantList weightDatas READ weightDatas NOTIFY weightDatasChanged)
    Q_PROPERTY(QString startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
    Q_PROPERTY(QString endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
    Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged)
    Q_PROPERTY(int currentMode READ currentMode WRITE setCurrentMode NOTIFY currentModeChanged)
    Q_PROPERTY(int accumulateMode READ accumulateMode WRITE setAccumulateMode NOTIFY accumulateModeChanged)
    Q_PROPERTY(int autoSave READ autoSave WRITE setAutoSave NOTIFY autoSaveChanged)
    Q_PROPERTY(int saveDays READ saveDays WRITE setSaveDays NOTIFY saveDaysChanged)
    Q_PROPERTY(int lowLevelThreshold READ lowLevelThreshold WRITE setlowLevelThreshold NOTIFY lowLevelThresholdChanged)
    Q_PROPERTY(int totalSilos READ totalSilos WRITE settotalSilos NOTIFY totalSilosChanged)
    Q_PROPERTY(int itemsPerPage READ itemsPerPage WRITE setItemsPerPage NOTIFY itemsPerPageChanged)
    Q_PROPERTY(int perPageShowtime READ perPageShowtime WRITE setPerPageShowtime NOTIFY perPageShowtimeChanged)        
    Q_PROPERTY(int ifshowTotal READ ifshowTotal WRITE setIfshowTotal NOTIFY ifshowTotalChanged)
    Q_PROPERTY(QString silosIDList READ silosIDList WRITE setSilosIDList NOTIFY silosIDListChanged)
    Q_PROPERTY(QString silosCapacityList READ silosCapacityList WRITE setSilosCapacityList NOTIFY silosCapacityListChanged)
    Q_PROPERTY(QString silosWeightList READ silosWeightList)
    Q_PROPERTY(QString silosUpdateTimeList READ silosUpdateTimeList)
    Q_PROPERTY(int commStatus READ commStatus NOTIFY commStatusChanged)
    Q_PROPERTY(QString silosName READ silosName WRITE setsilosName NOTIFY silosNameChanged)

    Q_SIGNALS:
        void refreshPageSignal();

public:
    explicit MyModBus(QObject* parent = nullptr);
    virtual ~MyModBus();

    Q_INVOKABLE QVariantList weightDatas() const;
    Q_INVOKABLE QString startTime();
    Q_INVOKABLE void setStartTime(QString startTime);
    Q_INVOKABLE QString endTime();
    Q_INVOKABLE void setEndTime(QString endTime);
    Q_INVOKABLE int currentPage();
    Q_INVOKABLE void setCurrentPage(int currentPage);

    Q_INVOKABLE int accumulateMode();
    Q_INVOKABLE void setAccumulateMode(int accumulateMode);
    Q_INVOKABLE int currentMode();
    Q_INVOKABLE void setCurrentMode(int currentMode);
    Q_INVOKABLE double accumulateZero();
    Q_INVOKABLE bool setAccumulateZero(double accumulateZero);
    Q_INVOKABLE int autoSave();
    Q_INVOKABLE bool setAutoSave(int autoSave);
    Q_INVOKABLE int saveDays();
    Q_INVOKABLE bool setSaveDays(int saveDays);

    Q_INVOKABLE bool init();
    Q_INVOKABLE bool setInit(bool init);
    Q_INVOKABLE bool downloadOTAPackage();
    Q_INVOKABLE bool setDownloadOTAPackage(bool downloadOTAPackage);

    Q_INVOKABLE QStringList comData();
    Q_INVOKABLE QString comName();
    Q_INVOKABLE QString qccid();
    Q_INVOKABLE bool cpin();
    Q_INVOKABLE int baudrate();
    Q_INVOKABLE int dataBit();
    Q_INVOKABLE int stopBit();
    Q_INVOKABLE int parity();

    Q_INVOKABLE QString comName4g();
    Q_INVOKABLE int baudrate4g();
    Q_INVOKABLE int dataBit4g();
    Q_INVOKABLE int stopBit4g();
    Q_INVOKABLE int parity4g();

    Q_INVOKABLE QString comNameEncoder();
    Q_INVOKABLE int baudrateEncoder();
    Q_INVOKABLE int dataBitEncoder();
    Q_INVOKABLE int stopBitEncoder();
    Q_INVOKABLE int parityEncoder();

    void connectSerialPort();
    void connectEncoder();
    void connect4g();
    Q_INVOKABLE QString softwareVersion();
    Q_INVOKABLE QString devDate();
    Q_INVOKABLE QString weight();
    Q_INVOKABLE int decimalPlaces();
    Q_INVOKABLE bool setDecimalPlaces(int decimalPlaces);
    Q_INVOKABLE int minGraduation();
    Q_INVOKABLE bool setMinGraduation(int minGraduation);
    Q_INVOKABLE QString unit();
    Q_INVOKABLE bool setUnit(QString unit);
    Q_INVOKABLE double upperUpperLimit();
    Q_INVOKABLE bool setUpperUpperLimit(double upperUpperLimit);
    Q_INVOKABLE double upperLimit();
    Q_INVOKABLE bool setUpperLimit(double upperLimit);
    Q_INVOKABLE double lowerLimit();
    Q_INVOKABLE bool setLowerLimit(double lowerLimit);
    Q_INVOKABLE double lowerLowerLimit();
    Q_INVOKABLE bool setLowerLowerLimit(double lowerLowerLimit);
    Q_INVOKABLE int steadyStateFiltering();
    Q_INVOKABLE bool setSteadyStateFiltering(int steadyStateFiltering);
    Q_INVOKABLE int digitalFiltering();
    Q_INVOKABLE bool setDigitalFiltering(int digitalFiltering);
    Q_INVOKABLE int slaveID();
    Q_INVOKABLE bool setSlaveID(int slaveID);
    Q_INVOKABLE int stabilityRange();
    Q_INVOKABLE bool setStabilityRange(int stabilityRange);
    Q_INVOKABLE int clearRange();
    Q_INVOKABLE bool setClearRange(int clearRange);
    Q_INVOKABLE int powerAutoZero();
    Q_INVOKABLE bool setPowerAutoZero(int powerAutoZero);
    Q_INVOKABLE int zeroTraceRange();
    Q_INVOKABLE bool setZeroTraceRange(int zeroTraceRange);
    Q_INVOKABLE int backlight();
    Q_INVOKABLE bool setbacklight(int backlight);
    Q_INVOKABLE bool setbacklightvalue(int value);
    Q_INVOKABLE void beep(int msecond);
    Q_INVOKABLE int screenSaveTime();
    Q_INVOKABLE bool setScreenSaveTime(int screenSaveTime);
    Q_INVOKABLE int aDSampleRate();
    Q_INVOKABLE bool setADSampleRate(int aDSampleRate);
    Q_INVOKABLE int maxRange();
    Q_INVOKABLE bool setMaxRange(int maxRange);
    Q_INVOKABLE int holdMode();
    //Q_INVOKABLE void setHoldMode(int holdMode);
    Q_INVOKABLE int holdTriggerCondition();
    //Q_INVOKABLE void setHoldTriggerCondition(int holdTriggerCondition);
    Q_INVOKABLE int zeroValue();
    Q_INVOKABLE bool setZeroValue(int zeroValue);
    Q_INVOKABLE int holdResult();
    Q_INVOKABLE int preIsStable1();
    //Q_INVOKABLE void setPreIsStable1(int preIsStable1);
    Q_INVOKABLE int preMinDuration1();
    //Q_INVOKABLE void setPreMinDuration1(int preMinDuration1);
    Q_INVOKABLE int preCondition1();
    //Q_INVOKABLE void setPreCondition1(int preCondition1);
    Q_INVOKABLE int preValue11();
    Q_INVOKABLE bool setPreValue11(int preValue11);
    Q_INVOKABLE int preValue21();
    Q_INVOKABLE bool setPreValue21(int preValue21);

    Q_INVOKABLE int preIsStable2();
    Q_INVOKABLE int preMinDuration2();
    Q_INVOKABLE int preCondition2();
    Q_INVOKABLE int preValue12();
    Q_INVOKABLE bool setPreValue12(int preValue12);
    Q_INVOKABLE int preValue22();
    Q_INVOKABLE bool setPreValue22(int preValue22);

    Q_INVOKABLE int preIsStable3();
    Q_INVOKABLE int preMinDuration3();
    Q_INVOKABLE int preCondition3();
    Q_INVOKABLE int preValue13();
    Q_INVOKABLE bool setPreValue13(int preValue13);
    Q_INVOKABLE int preValue23();
    Q_INVOKABLE bool setPreValue23(int preValue23);

    Q_INVOKABLE int preIsStable4();
    Q_INVOKABLE int preMinDuration4();
    Q_INVOKABLE int preCondition4();
    Q_INVOKABLE int preValue14();
    Q_INVOKABLE bool setPreValue14(int preValue14);
    Q_INVOKABLE int preValue24();
    Q_INVOKABLE bool setPreValue24(int preValue24);

    Q_INVOKABLE int stable();
    Q_INVOKABLE int normal();
    Q_INVOKABLE int zero();
    Q_INVOKABLE int positive();
    Q_INVOKABLE int batteryLevel();

    Q_INVOKABLE int current0();
    Q_INVOKABLE int collectTime();
    Q_INVOKABLE bool setCollectTime(int collectTime);

    Q_INVOKABLE int axisCount();
    Q_INVOKABLE bool setAxisCount(int axisCount);

    Q_INVOKABLE QString addrs();
    Q_INVOKABLE bool setAddrs(QString addrs);

    Q_INVOKABLE QString deviceID();
    Q_INVOKABLE QString deviceType();

    Q_INVOKABLE QVariantList factors();
    bool setFactors();
    Q_INVOKABLE QString hostName();
    Q_INVOKABLE bool setHostName(QString hostName);

    Q_INVOKABLE int port();
    Q_INVOKABLE bool setPort(int port);
//subTopic
    Q_INVOKABLE QString topic();
    Q_INVOKABLE bool setTopic(QString topic);
    Q_INVOKABLE QString subTopic();
    Q_INVOKABLE bool setSubTopic(QString subTopic);

    Q_INVOKABLE QString userName();
    Q_INVOKABLE bool setUserName(QString userName);

    Q_INVOKABLE QString password();
    Q_INVOKABLE bool setPassword(QString password);

    Q_INVOKABLE QString truckNo();
    Q_INVOKABLE bool setTruckNo(QString truckNo);

    Q_INVOKABLE QString clientID();
    Q_INVOKABLE bool setClientID(QString clientID);

    Q_INVOKABLE int mqttSwitch();
    Q_INVOKABLE bool setMqttSwitch(int mqttSwitch);


    Q_INVOKABLE int mqttInterval();
    Q_INVOKABLE bool setMqttInterval(int mqttInterval);

    Q_INVOKABLE int saveInterval();
    Q_INVOKABLE bool setSaveInterval(int saveInterval);


    Q_INVOKABLE int itemsPerPage();
    Q_INVOKABLE bool setItemsPerPage(int itemsPerPage);
    Q_INVOKABLE int perPageShowtime();
    Q_INVOKABLE bool setPerPageShowtime(int perPageShowtime);
    Q_INVOKABLE int totalSilos();
    Q_INVOKABLE bool settotalSilos(int totalSilos);
    Q_INVOKABLE int ifshowTotal();
    Q_INVOKABLE bool setIfshowTotal(int ifshowTotal);
    Q_INVOKABLE int lowLevelThreshold();
    Q_INVOKABLE bool setlowLevelThreshold(int lowLevelThreshold);
    Q_INVOKABLE QString silosIDList();
    Q_INVOKABLE bool setSilosIDList(QString silosIDList);
    Q_INVOKABLE QString silosCapacityList();
    Q_INVOKABLE bool setSilosCapacityList(QString silosCapacityList);
    Q_INVOKABLE QString silosWeightList();
    Q_INVOKABLE QString silosUpdateTimeList();
    Q_INVOKABLE int commStatus();
    Q_INVOKABLE QString silosName();
    Q_INVOKABLE bool setsilosName(QString silosNameList);


    void initsilosWeightList();
    void getData();
    bool InitSilosTable();
    QVector<double> Doolittle(int n,double *A,double *b);
    double* GetSubList(QVariantList list, int startIndex, int endIndex);
    void close();
    void refreshWeight();

    Q_INVOKABLE QString voltage0();
    Q_INVOKABLE QString voltage1();
    Q_INVOKABLE QString voltage2();
    Q_INVOKABLE QString voltage3();
    Q_INVOKABLE QString voltage4();
    Q_INVOKABLE QString voltage5();
    Q_INVOKABLE QString voltage6();
    Q_INVOKABLE QString voltage7();

    Q_INVOKABLE double calThreshold();
    Q_INVOKABLE bool setCalThreshold(double calThreshold);

    //sensorConnStatus
    Q_INVOKABLE int sensorConnStatus();
    Q_INVOKABLE void setSensorConnStatus(int sensorConnStatus);
    //sensorLastRevTime
    Q_INVOKABLE QString sensorLastRevTime();
    Q_INVOKABLE void setSensorLastRevTime(QString sensorLastRevTime);


    Q_INVOKABLE bool encoderConnStatus();
    Q_INVOKABLE void setEncoderConnStatus(bool encoderConnStatus);

    Q_INVOKABLE QString _4gLastRevTime();
    Q_INVOKABLE void set4gLastRevTime(QString _4gLastRevTime);

    Q_INVOKABLE QString encoderLastRevTime();
    Q_INVOKABLE void setEncoderLastRevTime(QString encoderLastRevTime);

    Q_INVOKABLE QString gpsLastRevTime();
    Q_INVOKABLE void setGpsLastRevTime(QString gpsLastRevTime);

    //_4gCPIN
    Q_INVOKABLE bool _4gCPIN();
    Q_INVOKABLE void set4gCPIN(bool _4gCPIN);
    //_4gConnStatus
    Q_INVOKABLE int _4gConnStatus();
    Q_INVOKABLE void set4gConnStatus(int _4gConnStatus);
    //_4gCEREG
    Q_INVOKABLE bool _4gCEREG();
    Q_INVOKABLE void set4gCEREG(bool _4gCEREG);
    //4gOpenMqttClient
    Q_INVOKABLE bool _4gOpenMqttClient();
    Q_INVOKABLE void set4gOpenMqttClient(bool _4gOpenMqttClient);
    //_4gConnMqttClient
    Q_INVOKABLE bool _4gConnMqttClient();
    Q_INVOKABLE void set4gConnMqttClient(bool _4gConnMqttClient);
//_4gSignal
    Q_INVOKABLE QString _4gSignal();
    Q_INVOKABLE void set4gSignal(QString _4gSignal);
    //_4gSubSuccess
    Q_INVOKABLE bool _4gSubSuccess();
    Q_INVOKABLE void set4gSubSuccess(bool _4gSubSuccess);

    Q_INVOKABLE QString apn();
    Q_INVOKABLE bool setApn(QString apn);
    Q_INVOKABLE QString url();
    Q_INVOKABLE bool setUrl(QString url);
    Q_INVOKABLE QString version();
    Q_INVOKABLE QString devTime();

    Q_INVOKABLE int encoderChannel();
    Q_INVOKABLE bool setEncoderChannel(int encoderChannel);
    Q_INVOKABLE int encoderFiltering();
    Q_INVOKABLE bool setEncoderFiltering(int encoderFiltering);
    Q_INVOKABLE int encoderDirection();
    Q_INVOKABLE bool setEncoderDirection(int encoderDirection);
    Q_INVOKABLE int encoderInterval();
    Q_INVOKABLE bool setEncoderInterval(int encoderInterval);

    Q_INVOKABLE int pulsePerRev();
    Q_INVOKABLE bool setPulsePerRev(int pulsePerRev);

    Q_INVOKABLE int sensorSlaveID();
    Q_INVOKABLE bool setSensorSlaveID(int sensorSlaveID);
    Q_INVOKABLE int encoderSlaveID();
    Q_INVOKABLE bool setEncoderSlaveID(int encoderSlaveID);

    Q_INVOKABLE QString angle();
    //Q_INVOKABLE bool setAngle(QString angle);

    Q_INVOKABLE QString weightNew();
    //Q_INVOKABLE bool setWeightNew(QString weightNew);
    Q_INVOKABLE QString voltage();
    //Q_INVOKABLE bool setVoltage(QString voltage);

    Q_INVOKABLE int encoderDecimalPlace();
    Q_INVOKABLE bool setEncoderDecimalPlace(int encoderDecimalPlace);
    //void checkUpgrade();
signals:
    void saveDaysChanged();
    void deviceIDChanged(QString deviceID);
    void deviceTypeChanged(QString deviceType);
    void weightDatasChanged(QVariantList weightDatas);
    void startTimeChanged();
    void endTimeChanged();
    void currentPageChanged();
    void currentModeChanged();
    void accumulateModeChanged();
    void accumulateZeroChanged();
    void autoSaveChanged();

    void initChanged(bool init);
    void downloadOTAPackageChanged(bool downloadOTAPackage);

    void comNameChanged(QString comName);
    void baudrateChanged(int baudrate);
    void dataBitChanged(int dataBit);
    void stopBitChanged(int stopBit);
    void parityChanged(int comName);

    void comName4gChanged(QString comName);
    void baudrate4gChanged(int baudrate);
    void dataBit4gChanged(int dataBit);
    void stopBit4gChanged(int stopBit);
    void parity4gChanged(int comName);

    void comNameEncoderChanged(QString comName);
    void baudrateEncoderChanged(int baudrate);
    void dataBitEncoderChanged(int dataBit);
    void stopBitEncoderChanged(int stopBit);
    void parityEncoderChanged(int comName);

    void softwareVersionChanged(QString version);
    void devDateChanged(QString devDate);
    void weightChanged(QString weight);
    void decimalPlacesChanged(int decimalPlaces);
    void minGraduationChanged(int minGraduation);
    void unitChanged(QString unit);
    void upperUpperLimitChanged(double upperUpperLimit);
    void upperLimitChanged(double upperLimit);
    void lowerLimitChanged(double lowerLimit);
    void lowerLowerLimitChanged(double lowerLowerLimit);
    void steadyStateFilteringChanged(int steadyStateFiltering);
    void digitalFilteringChanged(int digitalFiltering);
    void slaveIDChanged(int slaveID);
    void stabilityRangeChanged(int stabilityRange);
    void clearRangeChanged(int clearRange);
    void powerAutoZeroChanged(int powerAutoZero);
    void zeroTraceRangeChanged(int zeroTraceRange);
    void aDSampleRateChanged(int aDSampleRate);
    void maxRangeChanged(int maxRange);
    void holdModeChanged(int holdMode);
    void holdTriggerConditionChanged(int holdTriggerCondition);
    void zeroValueChanged(int zeroValue);
    void holdResultChanged(int holdResult);
    void preIsStable1Changed(int preIsStable1);
    void preMinDuration1Changed(int preMinDuration1);
    void preCondition1Changed(int preCondition1);
    void preValue11Changed(int preValue11);
    void preValue21Changed(int preValue21);
    void preIsStable2Changed(int preIsStable2);
    void preMinDuration2Changed(int preMinDuration2);
    void preCondition2Changed(int preCondition2);
    void preValue12Changed(int preValue12);
    void preValue22Changed(int preValue22);
    void preIsStable3Changed(int preIsStable3);
    void preMinDuration3Changed(int preMinDuration3);
    void preCondition3Changed(int preCondition3);
    void preValue13Changed(int preValue13);
    void preValue23Changed(int preValue23);
    void preIsStable4Changed(int preIsStable4);
    void preMinDuration4Changed(int preMinDuration4);
    void preCondition4Changed(int preCondition4);
    void preValue14Changed(int preValue14);
    void preValue24Changed(int preValue24);
    void backlightChanged(int backlight);
    void screenSaveTimeChanged(int screenSaveTime);
    void stableChanged(int stable);
    void normalChanged(int normal);
    void zeroChanged(int zero);
    void positiveChanged(int positive);
    void batteryLevelChanged(int batteryLevel);
    void current0Changed(int positive);
    void collectTimeChanged(int positive);
    void axisCountChanged(int axisCount);
    void normalParaRead();
    void addrsChanged(QString addrs);
    void cpinChanged(bool cpin);

    void hostNameChanged(QString hostName);
    void portChanged(int port);
    void topicChanged(QString topic);
    void subTopicChanged(QString subTopic);
    void userNameChanged(QString userName);
    void passwordChanged(QString password);
    void truckNoChanged(QString truckNo);
    void clientIDChanged(QString clientID);
    void mqttSwitchChanged(int mqttSwitch);
    void mqttIntervalChanged(int mqttInterval);

    void saveIntervalChanged(int saveInterval);

    void lowLevelThresholdChanged(int lowLevelThreshold);
    void totalSilosChanged(int totalSilos);
    void itemsPerPageChanged(int itemsPerPage);
    void perPageShowtimeChanged(int perPageShowtime);
    void ifshowTotalChanged(int ifshowTotal);

    void silosIDListChanged(QString silosIDList);
    void silosCapacityListChanged(QString silosCapacityList);
    void commStatusChanged(int commStatus);
    void silosNameChanged(QString silosName);

    void voltage0Changed(QString voltage0);
    void voltage1Changed(QString voltage1);
    void voltage2Changed(QString voltage2);
    void voltage3Changed(QString voltage3);
    void voltage4Changed(QString voltage4);
    void voltage5Changed(QString voltage5);
    void voltage6Changed(QString voltage6);
    void voltage7Changed(QString voltage7);

    void calThresholdChanged(double calThreshold);

    void sensorConnStatusChanged(int sensorConnStatus);
    void sensorLastRevTimeChanged(QString sensorLastRevTime);
    void _4gLastRevTimeChanged(QString _4gLastRevTime);
    void encoderLastRevTimeChanged(QString encoderLastRevTime);
    void gpsLastRevTimeChanged(QString gpsLastRevTime);
    //_4gCPIN
    void _4gCPINChanged(bool _4gCPIN);
    void _4gConnStatusChanged(int _4gConnStatus);
    void encoderConnStatusChanged(int encoderConnStatus);
    void _4gCEREGChanged(bool _4gCEREG);
    //4gOpenMqttClient
    void _4gOpenMqttClientChanged(bool _4gOpenMqttClient);
    void _4gConnMqttClientChanged(bool _4gConnMqttClient);
    void _4gSignalChanged(QString _4gSignal);
    void _4gSubSuccessChanged(bool _4gSubSuccess);

    void apnChanged(QString apn);
    void urlChanged(QString url);
    void encoderChannelChanged(int encoderChannel);
    void encoderFilteringChanged(int encorderFiltering);
    void encoderDirectionChanged(int encorderDirection);
    void encoderIntervalChanged(int encorderInterval);
    void pulsePerRevChanged(int pulsePerRev);
    void angleChanged(QString angle);
    void weightNewChanged(QString weightNew);
    void voltageChanged(QString voltage);
    void encoderDecimalPlaceChanged(int encoderDecimalPlace);

    void encoderSlaveIDChanged(int encoderSlaveID);
    void sensorSlaveIDChanged(int sensorSlaveID);
private:
    bool loadKernelModule(const QString &modulePath);

    bool showSumWeight = false;
    QString m_maxWeightTime = "";
    double m_maxWeight = std::numeric_limits<double>::lowest();

    int m_currentMode = 0;
    int m_accumulateMode = 0;
    QString m_startTime = "";
    QString m_endTime = "";
    int m_currentPage=-1;
    QVariantList m_weightDatas;
    bool m_init = true;
    bool m_downloadOTAPackage = false;

    bool saveEncoderParaDB(int channel, int interval, int direction, int filtering);
    bool saveEncoderParaSP(int direction, int filtering);

    double m_degreePerPulse;

    QString m_angle="0.0";

    bool m_encoderConnStatus = false;
    QString m_encoderLastRevTime="";

    void send4gDatas();
    void getAngle();
    void readAngle(QModbusReply* reply);
    mutable QMutex mutex;
    QReadWriteLock readWritelock;
    QSqlDatabase m_db;
    void collectData0();
    bool config4g();
    void configGPS();
    //QByteArray GenerateGPSCommand(uint8_t subGroupID);
    //cfgtype
    #define CFG_PRT         0x00
    #define CFG_MSG         0x01
    #define CFG_PPS         0x07
    #define CFG_CFG         0x09
    #define CFG_DOP         0x0A
    #define CFG_ELEV        0x0B
    #define CFG_NAVSAT      0x0C
    #define CFG_SPDHOLD     0x0F
    #define CFG_SIMPLERST   0x40
    #define CFG_SLEEP       0x41
    #define CFG_PWRCTL      0x42
    #define CFG_EPHSAVE     0x10
    QByteArray GPS_Config_Command(uint8_t cfgtype,QByteArray cfgdata);
    //msgtype
    #define GPS_MSG_GGA 0x00
    #define GPS_MSG_GLL 0x01
    #define GPS_MSG_GSA 0x02
    #define GPS_MSG_GRS 0x03
    #define GPS_MSG_GSV 0x04
    #define GPS_MSG_RMC 0x05
    #define GPS_MSG_VTG 0x06
    #define GPS_MSG_ZDA 0x07
    #define GPS_MSG_GST 0x08
    QByteArray GPS_CFG_MSG(uint8_t msgtype,uint8_t speed);
    QByteArray GPS_CFG_PWRCTL(uint32_t msecond);
    QByteArray Ql_Check_Quectel (QByteArray pData, unsigned int Length);
    void correctDateTime(QDateTime dateTime);

    void sendDataBy4g();
    
    int send4gData(QString str0, QString weight, QString unit, double lon, QString lonDir, double lat, QString latDir, double height, QString heightUnit, QString id);
    int sendsilosData();
    int MQTTsendString(QString topic,QString msg);
    int sendReqCfg();
    bool saveCollectData(QString str0, double weight, QString unit, double lon, QString lonDir, double lat, QString latDir, double height, QString heightUnit, QString truckNo, QString id, double lon_o, double lat_o,int mode, int scheduled);
    //bool saveWeightAndAngle(QString str0, double weight, QString unit, double angle);
    bool saveWeight(QString str0, double weight, QString unit, int mode, int scheduled);
    //QVector<double> leastSquaresFit(const QVector<double> x, const QVector<double> y, int order);
    void refreshData();
    void refreshVokltageData();
    bool setSendStatus(QString id);
    void sendArrRemoveObject(QString id);
    QTimer *timer;
    QTimer *timerEncoder;
    QTimer *timerbeep;
    QModbusReply *lastRequest = nullptr;
    QModbusClient *modbusDevice = nullptr;

    MyPrinter* pPrinter;
    
    QModbusClient *encoderModbusDevice = nullptr;
    QStringList m_comData;
    QString m_softwareVersion;
    QString m_devDate;

    //QString m_weight;
    QVariantMap m_weight;
    int m_decimalPlaces = 0;

    float m_zeroValue_0=0;

    int m_decimalPlaces0 = 0;
    int m_decimalPlaces1 = 0;
    int m_decimalPlaces2 = 0;
    int m_decimalPlaces3 = 0;
    int m_decimalPlaces4 = 0;
    int m_decimalPlaces5 = 0;
    int m_decimalPlaces6 = 0;
    int m_decimalPlaces7 = 0;

    int m_minGraduation;
    int m_steadyStateFiltering = 5;
    int m_digitalFiltering;
    int m_slaveID;
    int m_stabilityRange = 3;
    int m_clearRange = 99;
    int m_powerAutoZero = 0;
    int m_zeroTraceRange = 0;
    int m_aDSampleRate = 1;
    int m_maxRange;
    int m_holdMode;
    int m_holdTriggerCondition;
    int m_zeroValue;
    int m_holdResult;
    int m_preIsStable1;
    int m_preMinDuration1;
    int m_preCondition1;
    int m_preValue11;
    int m_preValue21;
    int m_preIsStable2;
    int m_preMinDuration2;
    int m_preCondition2;
    int m_preValue12;
    int m_preValue22;
    int m_preIsStable3;
    int m_preMinDuration3;
    int m_preCondition3;
    int m_preValue13;
    int m_preValue23;
    int m_preIsStable4;
    int m_preMinDuration4;
    int m_preCondition4;
    int m_preValue14;
    int m_preValue24;

    int m_stable = 0;
    int m_normal = 0;
    int m_zero = 0;
    int m_positive = 0;
    int m_batteryLevel = 0;

    int m_stable0 = 0;
    int m_normal0 = 0;
    int m_zero0 = 0;
    int m_positive0 = 0;

    int m_stable1 = 0;
    int m_normal1 = 0;
    int m_zero1 = 0;
    int m_positive1 = 0;

    int m_stable2 = 0;
    int m_normal2 = 0;
    int m_zero2 = 0;
    int m_positive2 = 0;

    int m_stable3 = 0;
    int m_normal3 = 0;
    int m_zero3 = 0;
    int m_positive3 = 0;

    int m_stable4 = 0;
    int m_normal4 = 0;
    int m_zero4 = 0;
    int m_positive4 = 0;

    int m_stable5 = 0;
    int m_normal5 = 0;
    int m_zero5 = 0;
    int m_positive5 = 0;

    int m_stable6 = 0;
    int m_normal6 = 0;
    int m_zero6 = 0;
    int m_positive6 = 0;

    int m_stable7 = 0;
    int m_normal7 = 0;
    int m_zero7 = 0;
    int m_positive7 = 0;

    int m_current0 = 0;
    QString m_addrs;

    QString m_str_silosIDList;
    QString m_str_CapacityList;
    QString m_str_silosName;

    QList<double> m_accumulateWeights;
    QString m_qccid;
    QModbusDataUnit readRequest(int startAddress, int numberOfEntries, int type = QModbusDataUnit::HoldingRegisters) const;
    QModbusDataUnit writeRequest(int startAddress, int numberOfEntries, int type = QModbusDataUnit::HoldingRegisters) const;
    int byteArrayToInt(QByteArray arr,  Endian endian = BigEndian);
    void collectData();
    QSerialPort* serialPort4g = nullptr;
    QSerialPort* serialPortGW = nullptr;
    int receBytes=0;

    bool isClosed=false;        //哦哦 不看这个。
    QString m_weightData;

    QString m_voltage="";
    QString m_weight_new="";
    QString m_voltage0=QString("");
    QString m_voltage1=QString("");
    QString m_voltage2=QString("");
    QString m_voltage3=QString("");
    QString m_voltage4=QString("");
    QString m_voltage5=QString("");
    QString m_voltage6=QString("");
    QString m_voltage7=QString("");

    int m_voltage0_=-1;
    int m_voltage1_=-1;
    int m_voltage2_=-1;
    int m_voltage3_=-1;
    int m_voltage4_=-1;
    int m_voltage5_=-1;
    int m_voltage6_=-1;
    int m_voltage7_=-1;
    //纬度
    double m_lat = std::numeric_limits<double>::lowest();
    double m_lat_o = std::numeric_limits<double>::lowest();
    //经度
    double m_lon = std::numeric_limits<double>::lowest();
    double m_lon_o = std::numeric_limits<double>::lowest();

    double m_height = std::numeric_limits<double>::lowest();
    QString m_lat_dir="";
    QString m_lon_dir="";
    QString m_height_unit="";
//    //纬度
//    double m_lat = 3903.491986;
//    //经度
//    double m_lon = 11704.418520;
//    double m_height = 19.3;
//    QString m_lat_dir="N";
//    QString m_lon_dir="E";
//    QString m_height_unit="M";

    QJsonArray arrToSend;

    QSqlQuery* m_query;

    QVariantList m_coefficients;
    QVariantList m_constants;

    int m_sensorConnStatus=false;
    //QDateTime m_sensorLastRevTime;
    QString m_sensorLastRevTimeStr="";
    QString m_4gLastRevTimeStr="";
    QString m_gpsLastRevTimeStr="";
    int m_4gConnStatus=false;
    QString m_4gSignal="";

    QByteArray buffer;
    QList<QByteArray> lstBuf;

    QByteArray gatewaybuffer;
    QList<QByteArray> lstGatewayBuf;
    
    void readWeight(QModbusReply* reply, int i);
    void readWeight(QModbusReply* reply);

    void readAdvPara(QModbusReply* reply);
    bool sendOTACommandQICSGP();
    bool sendOTACommandQIACT();
    bool sendOTACommandQHTTPCFG();
    bool sendOTACommandQHTTP();
    bool sendOTACommandDownload();
    bool UnzipOTAPackage();
    bool powerMode(bool isOn);
    bool switchToGPS(bool isOn);
    bool restart4g(bool isRestart);
    bool setVersionAndDevTime(QString version, QString devTime);
    bool saveComParas(QString comName,int baudrate,int dataBit,int stopBit,int parity, int type = 0);
    void sumWeights();
    void parse4gData(QByteArray temp);
public slots:
    void clearAccumulateWeights();
    void appendAccumulateWeights(QString weight);
    void showAccumulateWeightSum(bool isShown);

    bool exportToCsv(QString startTime, QString endTime);
    bool saveCurrentWeight(QString weight, QString unit);
    void correctTime(QString currentTime);
    void loadWeightData();
    bool saveClientID(QString clientID, QString deviceType);
    bool slotReadAdvPara();
    bool slotSaveEncoderPara(int channel, int direction, int filtering, int interval);
    bool slotClearAngle();
    bool slotZeroWeight();
    void onTimeOut();
    void onTimeOutEncoder();
    void BeepTimeOut();
    void getSoftwareVersion();
    void getDevDate();
    void getWeight();
    int getDecimalPlaces();
    int getMinGraduation();
    void findAndSendMQTT();
    void SendSilosMQTT();

    bool slotSaveComParas(QString comName,int baudrate,int dataBit,int stopBit,int parity, int type = 0);

    bool slotSaveComParas_new(QString comName,int baudrate,int dataBit,int stopBit,int parity, int slaveID, int type = 0);
    bool slotSaveMqttParas(QString hostName, int port, QString userName, QString password, int isOpen, QString truckNo, QString clientID);
    bool slotSaveNormalPara(double upperUpperLimit, double upperLimit, double lowerLimit, double lowerLowerLimit, int collectTime, int saveInterval, double accumulateZero, int autoSave, int saveDays, int backlight, int screenSaveTime);
    void slotPrintReceipt(float weight,float unitprice,float totalprice);
    void getSteadyStateFiltering();
    void getDigitalFiltering();
    void getSlaveID();
    void getStabilityRange();
    void getClearRange();
    void getPowerAutoZero();
    void getZeroTraceRange();
    void getADSampleRate();
    int getMaxRange();
    bool zeroCalibration();
    bool gainCalibration(int index, int value);
    bool gainCalibrationAll(int index, int value);
    bool gainCalibration(int index, int value, int deviceIndex);
    void reset();
    void getHoldMode();
    void getHoldTriggerCondition();
    void getZeroValue();
    void getHoldResult();
    void getPreIsStable1();
    void getPreMinDuration1();
    void getPreCondition1();
    void getPreValue11();
    void getPreValue21();
    bool setHoldModeCondition(int holdMode, int holdTriggerCondition);
    bool setPrePosPara(int posIndex, int isStable, int minDuration, int condition);
    void getPreIsStable2();
    void getPreMinDuration2();
    void getPreCondition2();
    void getPreValue12();
    void getPreValue22();
    void getPreIsStable3();
    void getPreMinDuration3();
    void getPreCondition3();
    void getPreValue13();
    void getPreValue23();
    void getPreIsStable4();
    void getPreMinDuration4();
    void getPreCondition4();
    void getPreValue14();
    void getPreValue24();
    bool resetAll(int deviceID);
    bool resetCal(int deviceID);
    bool resetPara(int deviceID);

    bool resetAll();
    bool resetCal();
    bool resetPara();
    //bool resetZeroValue();
    bool resetSwitch();
    void getStable();
    void getNormal();
    void getZero();
    void getPositive();
    void getCurrent0();
    void getNormalParas();
    void getVoltage();
    bool calculateFactor();
    void appendMatrixData(double constant);
    void clearMatrixData();
    int voltage(int deviceIndex);
    bool zeroCalibration(int deviceIndex);
    int getDecimalPlaces(int deviceId);
    int getMinGraduation(int deviceId);
    int getMaxRange(int deviceId);
    bool setDecimalPlaces(int decimalPlaces, int deviceId);
    bool setMinGraduation(int minGraduation, int deviceId);
    bool setMaxRange(int maxRange, int deviceId);
    void getCollectData0(int deviceIndex);
    bool setZeroValue_();
    bool setZeroWeight1(QString weight);
    bool resetZeroWeight_();
    //bool setZeroValue_(float value);

    int getStable(int deviceIndex);
    int getNormal(int deviceIndex);
    int getZero(int deviceIndex);
    int getPositive(int deviceIndex);

    void getCollectVoltage(int deviceIndex);
    int getVoltageById(int deviceIndex);
    int totalCount(QString startTime, QString endTime);
    bool saveOTAPara(QString apn, QString url);
    bool slotOTADownload();
    bool uDiskUpgrade();
    bool uDiskImportConfig();
    bool uDiskExportConfig();
    bool reBoot();
    bool programRestart();
    bool slotSwitchToGps(bool isOn);
    bool slotRestart4g(bool isRestart);
private slots:
    void slotReadVersion();
    void slotReadDevDate();
    void slotReadWeight(int i);

    void slotReadVoltage(int i);
    void slotReadDecimalPlaces();
    void slotReadDecimalPlaces(int i);
    void slotReadMinGraduation();
    void slotReadSteadyStateFiltering();
    void slotReadDigitalFiltering();
    void slotReadStabilityRange();
    void slotReadClearRange();
    void slotReadPowerAutoZero();
    void slotReadZeroTraceRange();
    void slotReadADSampleRate();
    void slotReadMaxRange();
    void slotReadHoldMode();
    void slotReadHoldTriggerCondition();
    void slotReadZeroValue();
    void slotReadHoldResult();
    void slotReadPreIsStable1();
    void slotReadPreMinDuration1();
    void slotReadPreCondition1();
    void slotReadPreValue11();
    void slotReadPreValue21();

    void slotReadPreIsStable2();
    void slotReadPreMinDuration2();
    void slotReadPreCondition2();
    void slotReadPreValue12();
    void slotReadPreValue22();

    void slotReadPreIsStable3();
    void slotReadPreMinDuration3();
    void slotReadPreCondition3();
    void slotReadPreValue13();
    void slotReadPreValue23();

    void slotReadPreIsStable4();
    void slotReadPreMinDuration4();
    void slotReadPreCondition4();
    void slotReadPreValue14();
    void slotReadPreValue24();

    void slotReadStable();
    void slotReadNormal();
    void slotReadZero();
    void slotReadPositive();
    void slotReadCurrent0();
    void slotReadVoltageData(int i);
    void slotReadCollectData();
    void slotReadCollectData_(int i);
    void slotCollectTimeChanged();
    void slotEncoderIntervalChanged();
    void slotReadNormalPara();
    void slotbacklightChanged();
    void readGPSData();
    void read4gData();

    void readGatewayData();

    void processGatewayData(const QByteArray &data);
    void parseGatewayData(QByteArray temp);
    
    void processPendingData(const QByteArray &data);
    //QString sendCommand(QString cmd, bool isRec, int waitInterval);
    void sendCommand(QString cmd);
    void sendGPSCommand(QByteArray data);
};

#endif // MYMODBUS_H
